package com.smart.electronic.fence.service.impl;

import com.smart.electronic.fence.mapper.UserMapper;
import com.smart.electronic.fence.pojo.User;
import com.smart.electronic.fence.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public int addUserInfo(User user) {
        User user1 = userMapper.selectByUserNameAndUserPassword(user.getUserName(),user.getUserPassword());
        if (user1!=null){
            return 0;
        }
        return userMapper.insert(user);
    }

    @Override
    public int removeById(BigInteger userId) {
        return userMapper.deleteById(userId);
    }

    @Override
    public int editById(User user) {
        return userMapper.updateById(user);
    }

    @Override
    public int exitByUserNameAndPwd(User user) {
        return userMapper.updateUserOnlineByUserNameAndPwd(user);
    }

    @Override
    public int editPwd(User user) {
        return userMapper.updatePwdByUserName(user);
    }

    @Override
    public int editOnlineByUser(User user) {
        return userMapper.updateUserOnlineByUserNameAndPwd(user);
    }

    @Override
    public User getById(BigInteger userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public User getByUserNameAndPwd(String userName, String userPassword) {
        return userMapper.selectByUserNameAndUserPassword(userName,userPassword);
    }

    @Override
    public List<User> getAll() {
        return userMapper.selectByAll();
    }
}
